<?php
class PlugAskModel extends Model {
	var $_table = 'plug_ask';
	
	var $ask_id_nak; //INT UNSIGNED NOT NULL AUTO_INCREMENT ,
	var $deleted_nr = 0; //TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否删除' ,
	var $status_sr = 'new'; //ENUM('new','pass','spam') NULL DEFAULT 'new' COMMENT '状态' ,
	var $ask_time_n = 0; //INT UNSIGNED NOT NULL COMMENT '提问时间' ,
	var $ask_ip_sr; //VARCHAR(32) NOT NULL COMMENT '提问时使用的IP' ,
	var $asker_name_sr; //VARCHAR(64) NOT NULL COMMENT '提问者姓名' ,
	var $asker_email_s; //VARCHAR(128) NULL COMMENT 'EMAIL' ,
	var $asker_phone_s; //VARCHAR(32) NULL COMMENT '电话或手机' ,
	var $asker_qq_s; //VARCHAR(15) NULL COMMENT 'QQ号码' ,
	var $related_content_id_s = '';
	var $anwer_name_s; //VARCHAR(64) NULL ,
	var $anwer_time_n = 0; //INT NOT NULL DEFAULT 0 ,
	var $ask_content_s = ''; //TEXT NULL ,
	var $anw_content_s = ''; //TEXT NULL ,
	/**
	 * 
	 * 新建一个留言
	 * @param string $name 留言人姓名
	 * @param string $content 留言内容
	 * @param string $email 留言者的EMAIL
	 * @param string $phone 电话
	 * @param string $qq QQ
	 * @param string $related_content_id 与该留言相关的内容编号(长度为16的字符)
	 * @return boolean 成功true,失败false
	 */
	public function newAsk($name, $content, $email = '', $phone = '', $qq = '', $related_content_id = '') {
		if (empty ( $name ) || empty ( $content )) {
			return false;
		}
		$data ['ask_time'] = time ();
		$data ['ask_ip'] = rinfo ( 'ip' );
		$data ['asker_name'] = $name;
		$data ['ask_content'] = $content;
		$data ['asker_phone'] = $phone;
		$data ['asker_email'] = $email;
		$data ['asker_qq'] = $qq;
		$data ['related_content_id'] = $related_content_id;
		$rst = $this->insert ( $data );
		if ($rst) {
			return $rst ['ask_id'];
		} else {
			return false;
		}
	}
	/**
	 * 
	 * 回复留言
	 * @param int $ask_id
	 * @param string $name 回复者姓名
	 * @param string $content 回复内容
	 * @return boolean 成功true,失败false
	 */
	public function replyAsk($ask_id, $name, $content) {
		if (empty ( $ask_id ) || empty ( $name ) || empty ( $content )) {
			return false;
		}
		$data ['anwer_time'] = time ();
		$data ['anwer_name'] = $name;
		$data ['status'] = 'pass';
		$data ['anwer_content'] = $content;
		$rst = $this->update ( $data, $ask_id );
		return $rst;
	}
}